package com.bysj.sausys.controller.backend;

import com.bysj.sausys.common.JsonData;
import com.bysj.sausys.service.ISysFileService;
import com.bysj.sausys.util.PropertiesUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 文件上传Controller
 *
 * @author WangZK
 */
@Api(description = "文件上传接口")
@Controller
@RequestMapping("/sys/file")
public class SysFileController {

    @Resource
    private ISysFileService sysFileService;

    /**
     * 上传社团相关文件
     *
     * @param fileName
     * @param request
     * @return
     */
    @ApiOperation(value = "上传社团相关文件接口")
    @RequestMapping(value = "uploadAssFile", method = RequestMethod.POST)
    @ResponseBody
    public String uploadAssFile(@ApiParam(value = "社团相关文件", required = true) @RequestParam(value = "fileName") MultipartFile fileName,
                                HttpServletRequest request) {
        //填充业务
        String path = request.getSession().getServletContext()
                .getRealPath(PropertiesUtil.getProperty("file.prefix") + "/" + PropertiesUtil.getProperty("file.ass"));
        return sysFileService.uploadAssFile(fileName, path);
    }

    /**
     * 上传下载资源文件
     *
     * @param fileName
     * @param request
     * @return
     */
    @ApiOperation(value = "上传下载资源文件接口")
    @RequestMapping(value = "uploadDataDowFile", method = RequestMethod.POST)
    @ResponseBody
    public String uploadDataDowFile(@ApiParam(value = "下载资源文件", required = true) @RequestParam(value = "fileName") MultipartFile fileName,
                                    HttpServletRequest request) {
        //填充业务
        String path = request.getSession().getServletContext()
                .getRealPath(PropertiesUtil.getProperty("file.prefix") + "/" + PropertiesUtil.getProperty("file.resources"));
        return sysFileService.uploadDataDowFile(fileName, path);
    }

    /**
     * 上传社团活动申请策划书
     */
    @ApiOperation(value = "上传社团活动申请策划书接口")
    @RequestMapping(value = "uploadActPlanFile", method = RequestMethod.POST)
    @ResponseBody
    public String uploadActPlanFile(@ApiParam(value = "社团活动申请策划书", required = true) @RequestParam(value = "fileName") MultipartFile fileName,
                                    HttpServletRequest request) {
        //填充业务
        String path = request.getSession().getServletContext()
                .getRealPath(PropertiesUtil.getProperty("file.prefix") + "/" + PropertiesUtil.getProperty("file.actPlan"));
        return sysFileService.uploadActPlanFile(fileName, path);
    }

    /**
     * 上传社团年审文件
     *
     * @param fileName
     * @param request
     * @return
     */
    @ApiOperation(value = "上传社团年审文件接口")
    @RequestMapping(value = "uploadAssAnnFile", method = RequestMethod.POST)
    @ResponseBody
    public String uploadAssAnnFile(@ApiParam(value = "社团相关文件", required = true) @RequestParam(value = "fileName") MultipartFile fileName,
                                HttpServletRequest request) {
        //填充业务
        String path = request.getSession().getServletContext()
                .getRealPath(PropertiesUtil.getProperty("file.prefix") + "/" + PropertiesUtil.getProperty("file.ann"));
        return sysFileService.uploadAssAnnFile(fileName, path);
    }

    /**
     * 上传推文图片
     *
     * @param fileName
     * @param request
     * @return
     */
    @ApiOperation(value = "上传推文图片接口")
    @RequestMapping(value = "uploadActArtFile", method = RequestMethod.POST)
    @ResponseBody
    public String uploadActArtFile(@ApiParam(value = "社团相关文件", required = true) @RequestParam(value = "fileName") MultipartFile fileName,
                                   HttpServletRequest request) {
        //填充业务
        String path = request.getSession().getServletContext()
                .getRealPath(PropertiesUtil.getProperty("file.prefix") + "/" + PropertiesUtil.getProperty("file.art"));
        return sysFileService.uploadActArtFile(fileName, path);
    }

}
